<template>
	<view>
		<view class="canvas">
			<canvas :canvas-id="code+''" :style="{width: `${qrcodeSize}px`, height: `${qrcodeSize}px`}" />
		</view>
	</view>
</template>

<script>
	import uQRCode from "@/utils/uqrcode.js";
	export default {
		name: "QRCode",
		props: ['code'],
		data() {
			return {
				qrcodeSize: 196,
			};
		},
		mounted() {
			if (this.code) {
				this.make(this.code + '')
			}
		},
		methods: {
			make(e) {
				uQRCode.make({
					canvasId: e,
					text: e,
					size: this.qrcodeSize,
					margin: 10,
					success: res => {
						this.qrcodeSrc = res
					},
					complete: () => {}
				})
			},
		}
	}
</script>

<style scoped>
	.canvas {
		margin-top: 50rpx;
		margin-bottom: 36rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #fff;
		border-radius: 15rpx;
		width: 206px;
		height: 206px;
	}
</style>